package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.PageHandler;
import org.dzms.commons.sqlHandler;
import org.dzms.entity.FoodRevDeta;
import org.dzms.entity.FoodReview;


public class foodReviewDAO {
	/**
	 * ========================================================
	 * 												食物评价查询
	 * ========================================================
	 */
	
	
	//查询所有食物评价信息
	public List<FoodReview> findAllFr() {
		String sql = "select *from foodreview";
		return DataHandler.query(sql, null, FoodReview.class);
	}
	//保存食物评价信息
		public void saveFe(FoodRevDeta fe) {
			String sql = "insert into foodrevdeta(fetaste, feenvironment, feservice, "
							 + "felike, fereview, feperpay, fefeatures,feapp,fefdsafe) values(?,?,?,?,?,?,?,?,?)";
			DataHandler.update(sql, new Object[]{fe.getFetaste(), fe.getFeenvironment(), fe.getFeservice(), 
														fe.getFelike(), fe.getFereview(), fe.getFeperpay(),
														fe.getFefeatures(), fe.getFeapp(), fe.getFefdsafe()});
		}
	//根据Id 把商户的一些基本详情拉出来
		public List<FoodReview> findById(int frid){
			String sql = "select * from foodreview where frid="+frid;
			return DataHandler.query(sql, null, FoodReview.class);
		}
	//删除食物评价信息
	public void deleteFr(int frid) {
		String sql = "delete from foodreview where frid=?";
		DataHandler.update(sql, new Object[]{frid});
	}
//	//新增食物评价信息
//	public void updateFr(FoodReview fr) {
//		String sql = "update foodreview set frname=?, frtaste=?, frenvionment=?, frservice=?"
//						+ "frlike=?, frreview=?, frperpay=?, frfeatures=?, frbusperpay=?, frbustaste=?"
//						+ "frbusenironment=?, frbusservice=?, frcomment=?, frusername=?, fruserreview=?"
//						+ "where frid=?";
//		DataHandler.update(sql, new Object[]{fr.getFrname(), fr.getFrtaste(), fr.getFrenvironment(),
//																		 fr.getFrservice(), fr.getFrlike(), fr.getFrreview(), fr.getFrperpay(), 
//																		 fr.getFrfeatures(), fr.getFrbusperpay(), fr.getFrbustaste(),
//																		 fr.getFrbusenironment(),  fr.getFrbusservice(), fr.getFrcomment(),
//																		 fr.getFrusername(), fr.getFrusername(), fr.getFrid()});
//	}
	public <E> List<E> findCurrentPageData(PageHandler handler) {
		String sql = "select * from foodreview limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},FoodReview.class);
	}

	public int findCountPage(PageHandler handler) {
		String sql = "select ceil(count(*)/?) from foodreview";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return Integer.parseInt(DataHandler.uniqueQuery(sql, new Object[]{handler.getPageSize()}).toString());
	}
	public <E>List<E> findFr(sqlHandler handler) {
		String sql = "select * from foodreview";
		if (handler.getCond() != null && handler.getCond().length() != 0) {
			sql += " where " + handler.getConditionSQL();
		}
		return DataHandler.query(sql, null, FoodReview.class);
	}
	
	
}
